/*
https://leetcode-cn.com/problems/reach-a-number/solution/dao-da-zhong-dian-shu-zi-by-leetcode/
 */
public class Solution754 {
    public int reachNumber(int target) {
        target=Math.abs(target);
        int cur=0,t=0;
        while (cur<target){
            t++;
            cur+=t;
        }
        if ((cur-target)%2==0){
            return t;
        }else {
            t++;
            cur=cur+t;
            if ((cur-target)%2==0){
                return t;
            }else {
                return t+1;
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution754().reachNumber(2));
    }
}
